package com.gykj.welleLTEIoT.controller;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gykj.admin.entity.User;
import com.gykj.welleLTEIoT.facade.IHomeRemote;

//@RestController

@Controller
public class HomeController {
	protected static Logger logger = LoggerFactory.getLogger(HomeController.class);
	@Autowired
	IHomeRemote homeRemote;
	

	@RequestMapping(value={"/login"},method= RequestMethod.GET)
    public String login(){
		return homeRemote.login();
    }

    @RequestMapping(value="/login",method=RequestMethod.POST)
    public String login(User user) {
    	Map<String,String> map = homeRemote.login(user);
    	logger.warn("return message: " + map.get("msg"));
    	return map.get("dispatch").toString();
    }
    
    @RequestMapping(value={"/usersPage",""})
    public String usersPage(){
        return "user/users";
//    	return AdminRomote.usersPage();
    }

    @RequestMapping(value={"/rolesPage"})
    public String rolesPage(){
//        return "role/roles";
        return homeRemote.rolesPage();
    }

    @RequestMapping(value={"/resourcesPage"})
    public String resourcesPage(){
//        return "resources/resources";
        return homeRemote.resourcesPage();
    }

    @RequestMapping(value={"/403"})
    public String forbidden(){
        return "403";
//        return homeRemote.forbidden();
    }
	
	@RequestMapping(value={"/hello/{name}"})
	@ResponseBody
	public  String index(@PathVariable(value = "name",required = false) String name) {
		return homeRemote.index(name);
	}
}
